<% include ../inc/head.ejs%>
<div class="container">

    <div class="col-md-8">
        <ul class="list-group">
        <% data.forEach(function(item){%>
            <li class="list-group-item article-list">
                <h4><a href="/articles/details/<%=item._id%>"><%=item.title.substr(0,20)%></a>
                    <% if(session_user!='' && item.user_id._id==session_user._id) {%>
                    <a href="/articles/edit/<%=item._id%>/<%=item.pic?item.pic:0%>/<%=item.user_id._id%>" class="btn btn-sm btn-warning">编辑</a> <a href="/articles/del/<%=item._id%>/<%=item.cat_id%>/<%=item.pic?item.pic:0%>/<%=item.user_id._id%>" class="btn btn-sm btn-danger">删除</a>
                    <%}%>
                </h4>
                <h5><i class="glyphicon glyphicon-dashboard"></i> <span><%=FormatDate(item.addtime)%></span>  <i class="glyphicon glyphicon-user"></i> <span><%=item.user_id.username%></span>  <i class="glyphicon glyphicon-list"></i> <span><%=item.cat_name%></span></h5>
                <div class="row">
                    <div class="col-md-4">
                        <% if(item.pic){ %>
                        <img src="/<%=item.pic%>" alt="<%=item.title%>" class="img-responsive">
                        <%}else{%>
                        <img src="/images/bj.png" alt="无缩略图" class="img-responsive" style="border:1px solid #ccc;">
                        <%}%>
                    </div>
                    <div class="col-md-8">
                        <div ><%=item.intro%></div>
                    </div>
                <div class="clearfix"></div>
                    <div class="pull-right readall"><a href="/articles/details/<%=item._id%>">阅读全文(<%=item.pv%>)</a></div>
                </div>
                <div class="clearfix"></div>
            </li>
            <%})%>
        </ul>
        <% if(pageTotal>1) {%>
        <div class="text-center">
            <ul class="pagination">
                <li><a href="javascript:;" class="searchzj">&laquo;</a></li>
                <% if(pageTotal<=6) {
                for(var i=1;i<=pageTotal;i++){
                    if(i==parseInt(currentPage)){
                        var cla='class=active';
                    }else{
                        var cla='';
                    }
                %>
                <li <%=cla%> > <a href="/articles/lst/<%=cat_id%>?pageNum=<%=i%>"><%=i%></a></li>
                <%}}else{%>
                <li class="active"><a href="/articles/lst/<%=cat_id%>?pageNum=<%=parseInt(currentPage)%>"><%=parseInt(currentPage)%></a></li>
                <%}%>
                <li><a href="javascript:;" class="searchjs">&raquo;</a></li>
            </ul>
        </div>
        <%}%>
    </div>
    <div class="col-md-4">
        <% include ../inc/right.ejs%>
    </div>
</div>
<% include ../inc/footer.ejs%>
<script>
    <!--页码-->
    $('.searchzj').click(function(){
        var cPage=$('.pagination .active').text();
        var page = cPage-1
        page=page<=0?cPage:page;
        window.location.href='/articles/lst/<%=cat_id%>?pageNum='+page;
    })
    $('.searchjs').click(function(){
        var cPage=$('.pagination .active').text();
        var page = parseInt(cPage)+1;
        var pageTotal = <%=parseInt(pageTotal)%>+0;
        page=page>=pageTotal?pageTotal:page;
        window.location.href='/articles/lst/<%=cat_id%>?pageNum='+page;
    })
</script>